package com.fdb.efp.nls.service.impl;

import com.fdb.basic.framework.core.base.FrameworkService;
import com.fdb.efp.nls.service.dao.BdRepayPlanTempDao;
import com.fdb.efp.nls.service.domain.BdRepayPlanTemp;
import com.fdb.efp.nls.service.facade.BdRepayPlanTempService;
import com.fdb.efp.nls.service.vo.BdRepayPlanTempVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

/**
 * <p>
 * ServiceImpl: 百度还款计划临时表
 * <p>
 * 
 * @author ligm
 * @date 2019-03-04
 */
@Service("bdRepayPlanTempService")
public class BdRepayPlanTempServiceImpl implements BdRepayPlanTempService, FrameworkService {

	private static Logger logger = LoggerFactory.getLogger(BdRepayPlanTempServiceImpl.class);

	@Autowired
	private BdRepayPlanTempDao bdRepayPlanTempDao;

	/**
	 * 新增操作
	 */
	public int insertBdRepayPlanTemp(BdRepayPlanTempVO inBdRepayPlanTempVo) {
		logger.debug("当前新增数据为:" + inBdRepayPlanTempVo.toString());
		int num = 0;
		try {
			BdRepayPlanTemp bdRepayPlanTemp = new BdRepayPlanTemp();
			beanCopy(inBdRepayPlanTempVo, bdRepayPlanTemp);
			num = bdRepayPlanTempDao.insertBdRepayPlanTemp(bdRepayPlanTemp);
		} catch (Exception e) {
			logger.error("新增数据发生异常!", e);
			num = -1;
		}
		logger.debug("当前新增数据条数为:" + num);
		return num;
	}

	/**
	 * 删除操作
	 */
	public int deleteByPk(BdRepayPlanTempVO inBdRepayPlanTempVo) {
		logger.debug("当前删除数据条件为:" + inBdRepayPlanTempVo);
		int num = 0;
		try {
			BdRepayPlanTemp bdRepayPlanTemp = new BdRepayPlanTemp();
			beanCopy(inBdRepayPlanTempVo, bdRepayPlanTemp);
			num = bdRepayPlanTempDao.deleteByPk(bdRepayPlanTemp);
		} catch (Exception e) {
			logger.error("删除数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:" + inBdRepayPlanTempVo + "删除的数据条数为" + num);
		return num;
	}

	/**
	 * 更新操作
	 */
	public int updateByPk(BdRepayPlanTempVO inBdRepayPlanTempVo) {
		logger.debug("当前修改数据为:" + inBdRepayPlanTempVo.toString());
		int num = 0;
		try {
			BdRepayPlanTemp bdRepayPlanTemp = new BdRepayPlanTemp();
			beanCopy(inBdRepayPlanTempVo, bdRepayPlanTemp);
			num = bdRepayPlanTempDao.updateByPk(bdRepayPlanTemp);
		} catch (Exception e) {
			logger.error("修改数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:" + inBdRepayPlanTempVo + "修改的数据条数为" + num);
		return num;
	}

	/**
	 * 查询操作
	 */
	public BdRepayPlanTempVO queryByPk(BdRepayPlanTempVO inBdRepayPlanTempVo) {

		logger.debug("当前查询参数信息为:" + inBdRepayPlanTempVo);
		try {
			BdRepayPlanTemp queryBdRepayPlanTemp = new BdRepayPlanTemp();
			beanCopy(inBdRepayPlanTempVo, queryBdRepayPlanTemp);
			BdRepayPlanTemp queryRslBdRepayPlanTemp = bdRepayPlanTempDao.queryByPk(queryBdRepayPlanTemp);
			if (Objects.nonNull(queryRslBdRepayPlanTemp)) {
				BdRepayPlanTempVO outBdRepayPlanTempVo = beanCopy(queryRslBdRepayPlanTemp, new BdRepayPlanTempVO());
				logger.debug("当前查询结果为:" + outBdRepayPlanTempVo.toString());
				return outBdRepayPlanTempVo;
			} else {
				logger.debug("当前查询结果为空!");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
		}
		return null;
	}

	/**
	 * 查询用户权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<BdRepayPlanTempVO> queryAllOwner(BdRepayPlanTempVO bdRepayPlanTempVo) {

		logger.debug("当前查询本人所属数据信息的参数信息为:");
		List<BdRepayPlanTempVO> list = null;
		try {
			List<BdRepayPlanTemp> bdRepayPlanTemps = bdRepayPlanTempDao.queryAllOwnerByPage(bdRepayPlanTempVo);
			logger.debug("当前查询本人所属数据信息的结果集数量为:" + bdRepayPlanTemps.size());
			pageSet(bdRepayPlanTemps, bdRepayPlanTempVo);
			list = (List<BdRepayPlanTempVO>) beansCopy(bdRepayPlanTemps, BdRepayPlanTempVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}

		return list;

	}

	/**
	 * 查询当前机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<BdRepayPlanTempVO> queryAllCurrOrg(BdRepayPlanTempVO bdRepayPlanTempVo) {

		logger.debug("当前查询本人所属机构数据信息的参数信息为:");
		List<BdRepayPlanTemp> bdRepayPlanTemps = bdRepayPlanTempDao.queryAllCurrOrgByPage(bdRepayPlanTempVo);
		logger.debug("当前查询本人所属机构数据信息的结果集数量为:" + bdRepayPlanTemps.size());
		List<BdRepayPlanTempVO> list = null;
		try {
			pageSet(bdRepayPlanTemps, bdRepayPlanTempVo);
			list = (List<BdRepayPlanTempVO>) beansCopy(bdRepayPlanTemps, BdRepayPlanTempVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}

		return list;

	}

	/**
	 * 查询当前机构及下属机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<BdRepayPlanTempVO> queryAllCurrDownOrg(BdRepayPlanTempVO bdRepayPlanTempVo) {

		logger.debug("当前查询本人所属机构及以下数据信息的参数信息为:");
		List<BdRepayPlanTemp> bdRepayPlanTemps = bdRepayPlanTempDao.queryAllCurrDownOrgByPage(bdRepayPlanTempVo);
		logger.debug("当前查询本人所属机构及以下数据信息的结果集数量为:" + bdRepayPlanTemps.size());
		List<BdRepayPlanTempVO> list = null;
		try {
			pageSet(bdRepayPlanTemps, bdRepayPlanTempVo);
			list = (List<BdRepayPlanTempVO>) beansCopy(bdRepayPlanTemps, BdRepayPlanTempVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		return list;
	}

	/**
	 * 查询百度同步过来的还款计划临时还款计划信息<br>
	 * 0.1:ludayong:2019年3月7日 上午9:48:59:增加 <br>
	 * 
	 * @author ludayong
	 * @since 2019年3月7日 上午9:48:59
	 * @date 2019年3月7日 上午9:48:59
	 * @version 0.1
	 */
	@SuppressWarnings("unchecked")
	public List<BdRepayPlanTempVO> queryAllLoanId(BdRepayPlanTempVO bdRepayPlanTempVo) {
		logger.debug("当前查询本人所属数据信息的参数信息为:");
		List<BdRepayPlanTempVO> list = null;
		try {
			List<BdRepayPlanTemp> bdRepayPlanTemps = bdRepayPlanTempDao.queryAllLoanIdByPage(bdRepayPlanTempVo);
			logger.debug("当前查询本人所属数据信息的结果集数量为:" + bdRepayPlanTemps.size());
			pageSet(bdRepayPlanTemps, bdRepayPlanTempVo);
			list = (List<BdRepayPlanTempVO>) beansCopy(bdRepayPlanTemps, BdRepayPlanTempVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		return list;
	}

	/**
	 * 根据还款计划号查询百度同步过来的还款计划临时还款计划信息<br>
	 * 0.1:ludayong:2019年3月7日 上午9:48:59:增加 <br>
	 * 
	 * @author ludayong
	 * @since 2019年3月7日 上午9:54:27
	 * @date 2019年3月7日 上午9:54:27
	 * @version 0.1
	 */
	@SuppressWarnings("unchecked")
	public List<BdRepayPlanTempVO> queryBdRepayPlanTempByLoanId(BdRepayPlanTempVO bdRepayPlanTempVo) {
		logger.debug("当前查询本人所属数据信息的参数信息为:");
		List<BdRepayPlanTempVO> list = null;
		try {
			List<BdRepayPlanTemp> bdRepayPlanTemps = bdRepayPlanTempDao.queryBdRepayPlanTempByLoanId(bdRepayPlanTempVo);
			logger.debug("当前查询本人所属数据信息的结果集数量为:" + bdRepayPlanTemps.size());
			list = (List<BdRepayPlanTempVO>) beansCopy(bdRepayPlanTemps, BdRepayPlanTempVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		return list;
	}

	/**
	 * 
	 * 分页查询【还款计划临时表】 <br>
	 * 0.1:ludayong:2019年3月23日 下午12:11:04:新增 <br>
	 * 
	 * @author ludayong
	 * @since 2019年3月23日 下午12:11:04
	 * @date 2019年3月23日 下午12:11:04
	 * @version 0.1
	 */
	@SuppressWarnings("unchecked")
	@Override
	public List<BdRepayPlanTempVO> queryByPage(BdRepayPlanTempVO bdRepayPlanTempVO) {
		String msg1 = "分页查询还款计划临时表";
		logger.debug(msg1, "message {}");
		List<BdRepayPlanTempVO> list = null;
		try {
			List<BdRepayPlanTemp> BdRepayPlanTemps = bdRepayPlanTempDao.queryByPage(bdRepayPlanTempVO);
			list = (List<BdRepayPlanTempVO>) beansCopy(BdRepayPlanTemps, BdRepayPlanTempVO.class);

		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);

		}
		if(list != null) {
			String msg2 = "查询的数据为大小为 " + list.size();
			logger.debug(msg2, "message {}");
		}
		return list;
	}

	/**
	 * 
	 * 统计【还款计划临时表】数据量 <br>
	 * 0.1:ludayong:2019年3月23日 下午12:11:10:新增 <br>
	 * 
	 * @author ludayong
	 * @since 2019年3月23日 下午12:11:10
	 * @date 2019年3月23日 下午12:11:10
	 * @version 0.1
	 */
	@Override
	public int queryCount() {
		String msg1 = "查询【还款计划临时表】表中数据量大小";
		logger.debug(msg1, "message {}");
		int num = 0;
		try {
			num = bdRepayPlanTempDao.queryCount();
		} catch (Exception e) {
			String msg2 = "查询【还款计划临时表】表中数据量大小出错" + e;
			logger.debug(msg2, "message {}");
			num = -1;
		}
		return num;
	}
}
